package com.sevattal.service.leaves.controller;


import com.sevattal.common.base.result.R;
import com.sevattal.service.leaves.entity.Emp;
import com.sevattal.service.leaves.entity.Material;
import com.sevattal.service.leaves.service.EmpService;
import com.sevattal.service.leaves.service.MaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 物资表 前端控制器
 * </p>
 *
 * @author Sevattal
 * @since 2021-08-28
 */
@Api(tags = "物资信息管理")
@RestController
@RequestMapping("/admin/leaves/material")
public class MaterialController {

    @Autowired
    private MaterialService materialService;

    @ApiOperation("新建物资")
    @PostMapping("createMaterial")
    public R createMaterial(@ApiParam(value = "物资对象",required = true) @RequestBody Material material){
        boolean result = materialService.createMaterial(material);
        if (result) {
            return R.ok().message("创建成功");
        }else{
            return R.error().message("创建失败");
        }
    }

    @ApiOperation("更新物资")
    @PutMapping("updateMaterial")
    public R updateMaterial(@ApiParam(value = "物资对象",required = true) @RequestBody Material material){
        boolean result = materialService.updateMaterial(material);
        if (result) {
            return R.ok().message("修改成功");
        }else{
            return R.error().message("修改失败");
        }
    }

    @ApiOperation("删除物资")
    @DeleteMapping("deleteMaterial/{id}")
    public R deleteMaterial(@ApiParam(value = "物资对象",required = true) @PathVariable String id){
        boolean result = materialService.deleteMaterial(id);
        if (result) {
            return R.ok().message("删除成功");
        }else{
            return R.error().message("删除失败");
        }
    }

    @ApiOperation("获取物资列表")
    @PostMapping("getMaterialList")
    public R getMaterialList(@ApiParam(value = "物资对象",required = true) @RequestBody Material material){
        List<Material> result = materialService.getMaterialList(material);
        return R.ok().data("materialList",result);
    }

    @ApiOperation("获取指定物资")
    @GetMapping("getMaterial/{id}")
    public R getMaterial(@ApiParam(value = "物资对象",required = true) @PathVariable String id){
        Material result = materialService.getMaterial(id);
        return R.ok().data("materialInfo",result);
    }



}

